<!doctype html>
<html class="x-admin-sm">
    <head>
        <meta charset="UTF-8">
        <title>CRM客户关系管理系统</title>
		<!--<title>后台登录-X-admin2.2</title>-->
        <meta name="renderer" content="webkit|ie-comp|ie-stand">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <meta http-equiv="Cache-Control" content="no-siteapp" />
        <link rel="stylesheet" href="./css/font.css">
        <link rel="stylesheet" href="./css/xadmin.css">
        <!-- <link rel="stylesheet" href="./css/theme5.css"> -->
        <script src="./lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="./js/xadmin.js"></script>
        <script type="text/javascript" src="./js/jquery.min.js"></script>
        <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
        <!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
        <script>
        	layui.use(['layer','form'],function(){
				var layer = layui.layer;
				var form=layui.form;
				var $=layui.$;
				var userId = sessionStorage.getItem("userId");
				var LoginName = sessionStorage.getItem("LoginName");
				
				var getStatus = function(){
					$.post("/userchecks/getUsers",{
		        		UserId:sessionStorage.getItem("userId"),
		        	},function(res){
		        		btnRender(res.code,res.msg);
		        	},"json")
				}
				//gmw
        	getStatus();
        	var btnRender=function(status,msg){
        		console.log(status)
        		console.log(msg)	
				var btn = $("#qianDao").html(msg);
				if(status=="0"){
				
				}else if(status=="1"){
        			btn.addClass("layui-btn-normal")
        		}else{
        			$("#qianDao").html(msg)
        			btn.addClass("layui-btn-disabled").attr("disabled",true)
        		}
        		btn.show();
        	}
        	
        	form.on('submit(qianDao)',function(){
        		$.post("/userchecks/addUserchecks",{
	        		UserId:sessionStorage.getItem("userId"),
	        		UserName:sessionStorage.getItem("LoginName")
	        	},function(res){
	        		layer.msg(res.msg)
	        		if(res.code=="0"){
	        			getStatus()
	        		}
	        		
	        	},"json")
        	});
				console.log(userId)
				if(userId==null){
					layer.alert("用户身份已过期,请重新登录",{icon:3},function(){
						window.location.href="login.html";
					})
				}
				$("#LoginName").html(LoginName)
				$.post("",{},function(res){
					
				},"json")
			})
            // 是否开启刷新记忆tab功能
            var is_remember = false;
        </script>
    </head>
    <body class="index">
        <!-- 顶部开始 -->
        <div class="container">
            <div class="logo">
                <!--<a href="./index.html">CRM客户关系管理系统</a></div>-->
                <a href="#">CRM客户关系管理系统</a></div>
            <div class="left_open">
                <a><i title="展开左侧栏" class="iconfont">&#xe699;</i></a>
            </div>
            <!--<ul class="layui-nav left fast-add" lay-filter="">
                <li class="layui-nav-item">
                    <a href="javascript:;">+新增</a>
                    <dl class="layui-nav-child">
                        
                        <dd>
                            <a onclick="xadmin.open('最大化','http://www.baidu.com','','',true)">
                                <i class="iconfont">&#xe6a2;</i>弹出最大化</a></dd>
                        <dd>
                            <a onclick="xadmin.open('弹出自动宽高','http://www.baidu.com')">
                                <i class="iconfont">&#xe6a8;</i>弹出自动宽高</a></dd>
                        <dd>
                            <a onclick="xadmin.open('弹出指定宽高','http://www.baidu.com',500,300)">
                                <i class="iconfont">&#xe6a8;</i>弹出指定宽高</a></dd>
                        <dd>
                            <a onclick="xadmin.add_tab('在tab打开','member-list.html')">
                                <i class="iconfont">&#xe6b8;</i>在tab打开</a></dd>
                        <dd>
                            <a onclick="xadmin.add_tab('在tab打开刷新','member-del.html',true)">
                                <i class="iconfont">&#xe6b8;</i>在tab打开刷新</a>
                        </dd>
                        
                    </dl>
                </li>
            </ul>-->
            <ul class="layui-nav right" lay-filter="">
			<li class="layui-nav-item to-index">
				<button lay-filter="qianDao" style="display: none" lay-submit=""
					class="layui-btn" id="qianDao">签到</button>
			</li>
			<li class="layui-nav-item">
                    <a href="javascript:;" id="LoginName">admin</a>
                    <dl class="layui-nav-child">
                        <!-- 二级菜单 -->
                        <dd>
                            <a onclick="xadmin.open('个人信息','http://www.baidu.com')">个人信息</a></dd>
                        <dd>
                            <a onclick="xadmin.open('切换帐号','http://www.baidu.com')">切换帐号</a></dd>
                        <dd>
                            <a class="out">退出</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item to-index">
                    <a href="/">前台首页</a></li>
            </ul>
        </div>
        <!-- 顶部结束 -->
        <!-- 中部开始 -->
        <!-- 左侧菜单开始 -->
        <div class="left-nav">
            <div id="side-nav">
                <ul id="nav">
                    
                </ul>
            </div>
        </div>
        <!-- <div class="x-slide_left"></div> -->
        <!-- 左侧菜单结束 -->
        <!-- 右侧主体开始 -->
        <div class="page-content">
            <div class="layui-tab tab" lay-filter="xbs_tab" lay-allowclose="false">
                <ul class="layui-tab-title">
                    <li class="home">
                        <i class="layui-icon">&#xe68e;</i>我的桌面</li></ul>
                <div class="layui-unselect layui-form-select layui-form-selected" id="tab_right">
                    <dl>
                        <dd data-type="this">关闭当前</dd>
                        <dd data-type="other">关闭其它</dd>
                        <dd data-type="all">关闭全部</dd></dl>
                </div>
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">
                        <iframe src='./welcome.html' frameborder="0" scrolling="yes" class="x-iframe"></iframe>
                    </div>
                </div>
                <div id="tab_show"></div>
            </div>
        </div>
        <div class="page-content-bg"></div>
        <style id="theme_style"></style>
        <!-- 右侧主体结束 -->
        <!-- 中部结束 -->
    </body>
<script type="text/javascript">
	var mdata = null;
	var module={
		getModuleTree : function(data){
			var tree = [];
			$(data).each(function(index,item){
				if(item.ParentId==0){
					item.rank=0;
					tree.push(module.getModuleChildren(item,data));
				}
			})
			console.log(tree)
			module.setModuleTree(tree);
		},getModuleChildren:function(thisModule,data){
			$(data).each(function(index,item){
				if(item.ParentId==thisModule.Id){
					var rank = item.rank=thisModule.rank+1;
					if(thisModule.children==null){
						thisModule.children=[];
					}
					thisModule.children.push(module.getModuleChildren(item,data));
				}
			})
			return thisModule;
		},setModuleTree:function(tree){
			if(tree.length==0){
				xadmin.add_tab('暂无权限','/page/module-err.html',true)
				/*$("#nav").append(`
					<div style="text-align:center;margin-top:50px;">
						<i class="layui-icon layui-icon-face-cry" style="font-size: 80px; color: red;"></i>
						<div style="font-size:15px;">
							您没有任何模块的权限
							<br/>
							请联系管理员授予权限!
						</div>
					</div>
				`)*/
			}
			$(tree).each(function(index,item){
				var ul = `<ul class="sub-menu" node="${item.Id}"></ul>`
				var dom = `
						<li>
	                        <a href="javascript:;">
	                            <i class="iconfont left-nav-li" lay-tips="${item.Name}">&#xe6b8;</i>
	                            <cite>${item.Name}</cite>
	                            <i class="iconfont nav_right">&#xe697;</i></a>
	                        ${ul}
	               		</li>
					`  
				if(item.children==null){
					ul="";
					dom = `
							<li>
		                        <a href="javascript:;">
		                            <i class="iconfont left-nav-li" lay-tips="${item.Name}">&#xe6b8;</i>
		                            <cite>${item.Name}</cite>
		                        ${ul}
		               		</li>
	               		`
	               	$("#nav").append(dom)
				}else{
					$("#nav").append(dom)
					module.setModuleChildren(item.children);
				}
				
				
			})
		},setModuleChildren:function(tree){
			$(tree).each(function(index,item){
				var ul = `<ul class="sub-menu" node="${item.Id}"></ul>`
				var dom = `
							<li>
                                <a onclick="xadmin.add_tab('${item.Name}','${item.Path}')">
                                    <i class="iconfont">&#xe6a7;</i>
                                    <cite>${item.Name}</cite></a>
                            </li>
                          `
				if(item.children!=null){
					dom = `
							<li>
		                        <a href="javascript:;">
		                            <i class="iconfont left-nav-li" lay-tips="${item.Name}">&#xe6b8;</i>
		                            <cite>${item.Name}</cite>
		                            <i class="iconfont nav_right">&#xe697;</i></a>
		                        ${ul}
		               		</li>
                          `
					$("[node='"+item.ParentId+"']").append(dom)
					module.setModuleChildren(item.children);
				}else{
					$("[node='"+item.ParentId+"']").append(dom);
				}
				
			})
			
		}
		
	}
	$.post("/modules/getModulesByUid",{uid:sessionStorage.getItem("userId")},function(res){
		module.getModuleTree(res)
	},"json")
	$(".out").click(function(){
		sessionStorage.removeItem("userId")
		location.href="./login.html";
	})
</script>
</html>